<!--
选择来源
value           =====>   双向数据绑定，v-model
-->
<template>
  <a-select
      v-model:value="defaultValue"
      style="width: 100%"
      show-search
      allowClear
      :options="selectOptions"
      :placeholder="placeholder"
      @change="onChange"
  ></a-select>
</template>

<script setup>
import { computed, onMounted, ref, watch } from 'vue'
const emit = defineEmits(['update:value'])
const props = defineProps({
  value: {
    type: [String, null],
    default: null
  },
  placeholder: {
    type: String,
    default: '请选择来源'
  }
})
const visible = ref(false)
const defaultValue = ref('')
const selectOptions = ref([
  {"label": "促销活动", "value": "促销活动"},
  {"label": "搜索引擎", "value": "搜索引擎"},
  {"label": "广告", "value": "广告"},
  {"label": "转介绍", "value": "转介绍"},
  {"label": "线上注册", "value": "线上注册"},
  {"label": "线上询价", "value": "线上询价"},
  {"label": "预约上门", "value": "预约上门"},
  {"label": "陌拜", "value": "陌拜"},
  {"label": "招商资源", "value": "招商资源"},
  {"label": "公司资源", "value": "公司资源"},
  {"label": "展会资源", "value": "展会资源"},
  {"label": "个人资源", "value": "个人资源"},
  {"label": "电话咨询", "value": "电话咨询"},
  {"label": "邮件咨询", "value": "邮件咨询"}
])

watch(() => props.value, (curr, old) => {
  defaultValue.value = curr
})

onMounted(() => {
  defaultValue.value = props.value
})

const onChange = (value) => {
  console.log(value)
  emit('update:value', value)
}

</script>

<style lang="scss" scoped>
</style>
